
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TrainingsApp.Model;
using TrainingsApp.Helper;
using WisDragon.Framework.Data.DataAccess;

namespace TrainingsApp.DAL
{
    public class TS_Preview_DAL
    {

        public static List<TS_Preview_Entity> TS_Preview_ListByTeacherAndChapter(long schoolId, long classId, long teacherId, long chapterId)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_ListByTeacherAndChapter");
                cmd.SetParameterValue("@ChapterId", chapterId);
                cmd.SetParameterValue("@TeachId", teacherId);
                cmd.SetParameterValue("@SchoolId", schoolId);
                cmd.SetParameterValue("@ClassId", classId);
                return cmd.ExecuteEntityList<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return new List<TS_Preview_Entity>(0);
        }

        public static TS_Preview_Collecion TS_Preview_ListByPaging(Dictionary<string, object> parameters, int pageSize, int pageIndex)
        {
            TS_Preview_Collecion list = new TS_Preview_Collecion();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_ListByPaging");
                Utility.BuilderCommandParameter(parameters, cmd);
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_Preview_Entity> pageList = cmd.ExecuteEntityList<TS_Preview_Entity>();
                list.TS_Preview_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return list;
        }

        public static TS_Preview_Collecion TS_Preview_ListByPaging2(Dictionary<string, object> parameters, int pageSize, int pageIndex)
        {
            TS_Preview_Collecion list = new TS_Preview_Collecion();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_ListByPaging2");
                Utility.BuilderCommandParameter(parameters, cmd);
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_Preview_Entity> pageList = cmd.ExecuteEntityList<TS_Preview_Entity>();
                list.TS_Preview_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return list;
        }

        public static TS_Preview_Collecion TS_Preview_QuickQueryListByPaging(Dictionary<string, object> parameters, int pageSize, int pageIndex)
        {
            TS_Preview_Collecion list = new TS_Preview_Collecion();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_QuickQueryListByPaging");
                Utility.BuilderCommandParameter(parameters, cmd);
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_Preview_Entity> pageList = cmd.ExecuteEntityList<TS_Preview_Entity>();
                list.TS_Preview_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return list;
        }

        public static TS_Preview_Collecion TS_Preview_StudentListByPaging(Dictionary<string, object> parameters, int pageSize, int pageIndex)
        {
            TS_Preview_Collecion list = new TS_Preview_Collecion();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_StudentListByPaging");
                Utility.BuilderCommandParameter(parameters, cmd);
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_Preview_Entity> pageList = cmd.ExecuteEntityList<TS_Preview_Entity>();
                list.TS_Preview_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return list;
        }

        public static TS_Preview_Entity TS_Preview_View(System.Guid PreviewId)
        {
            TS_Preview_Entity c = default(TS_Preview_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_View");
                cmd.SetParameterValue("@PreviewId", PreviewId);
                c = cmd.ExecuteEntity<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static List<TS_Preview_Entity> TS_Preview_ViewByBatch(System.Guid batch)
        {
            List<TS_Preview_Entity> c = new List<TS_Preview_Entity>();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_ViewByBatch");
                cmd.SetParameterValue("@Batch", batch);
                c = cmd.ExecuteEntityList<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }


        public static TS_Preview_Entity TS_Preview_Add(TS_Preview_Entity entity)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_Add");
                cmd.SetParameterValue("@PreviewId", entity.PreviewId);
                cmd.SetParameterValue("@TeachId", entity.TeachId);
                cmd.SetParameterValue("@SchoolId", entity.SchoolId);
                cmd.SetParameterValue("@ClassId", entity.ClassId);
                cmd.SetParameterValue("@ChapterId", entity.ChapterId);
                cmd.SetParameterValue("@CourseId", entity.CourseId);
                cmd.SetParameterValue("@MaterialsId", entity.MaterialsId);
                cmd.SetParameterValue("@QuestionId", entity.QuestionId);
                cmd.SetParameterValue("@PublishDate", entity.PublishDate);
                cmd.SetParameterValue("@ReferenceCount", entity.ReferenceCount);
                cmd.SetParameterValue("@RefBy", entity.RefBy);
                cmd.SetParameterValue("@Batch", entity.Batch);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return entity;
        }

        public static void TS_Preview_Update(TS_Preview_Entity entity)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_Update");
                cmd.SetParameterValue("@PreviewId", entity.PreviewId);
                cmd.SetParameterValue("@TeachId", entity.TeachId);
                cmd.SetParameterValue("@SchoolId", entity.SchoolId);
                cmd.SetParameterValue("@ClassId", entity.ClassId);
                cmd.SetParameterValue("@ChapterId", entity.ChapterId);
                cmd.SetParameterValue("@CourseId", entity.CourseId);
                cmd.SetParameterValue("@MaterialsId", entity.MaterialsId);
                cmd.SetParameterValue("@QuestionId", entity.QuestionId);
                cmd.SetParameterValue("@PublishDate", entity.PublishDate);
                cmd.SetParameterValue("@ReferenceCount", entity.ReferenceCount);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
        }

        public static void TS_Preview_Delete(System.Guid PreviewId)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_Delete");
                cmd.SetParameterValue("@PreviewId", PreviewId);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
        }

        public static string TS_Question_GetFirstPreviewByQuestionId(System.Guid QuestionId)
        {
            string c = default(String);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_GetFirstPreviewByQuestionId");
                cmd.SetParameterValue("@QuestionId", QuestionId);
                c = Convert.ToString(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Preview_Entity TS_Question_IsPreviewPublish(Dictionary<string, object> parameters)
        {
            TS_Preview_Entity c = default(TS_Preview_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_IsPreviewPublish");
                Utility.BuilderCommandParameter(parameters, cmd);
                c = cmd.ExecuteEntity<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Preview_Entity TS_Question_IsPreviewPublish2(Dictionary<string, object> parameters)
        {
            TS_Preview_Entity c = default(TS_Preview_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Question_IsPreviewPublish2");
                Utility.BuilderCommandParameter(parameters, cmd);
                c = cmd.ExecuteEntity<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static List<TS_Preview_Entity> TS_Preview_PreviewGroupByTeacher(System.Guid PreviewId)
        {
            List<TS_Preview_Entity> c = new List<TS_Preview_Entity>();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_PreviewGroupByTeacher");
                cmd.SetParameterValue("@PreviewId", PreviewId);
                c = cmd.ExecuteEntityList<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Preview_Entity TS_Preview_ViewGroupByPreviewId(System.Guid PreviewId)
        {
            TS_Preview_Entity c = default(TS_Preview_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_ViewGroupByPreviewId");
                cmd.SetParameterValue("@PreviewId", PreviewId);
                c = cmd.ExecuteEntity<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static List<TS_Preview_Entity> TS_Preview_GetClassesByQuestionId(Dictionary<string, object> parameters)
        {
            List<TS_Preview_Entity> c = new List<TS_Preview_Entity>();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Preview_GetClassesByQuestionId");
                Utility.BuilderCommandParameter(parameters, cmd);
                c = cmd.ExecuteEntityList<TS_Preview_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }
    }
}
